<template>
	<view>
		<my-search @my-click="jump"></my-search>
		<view class="content">
			<scroll-view class="left-scroll-view" scroll-y :style="{height:wh+'px'} ">
				<block v-for="(item,index) in cateList" :key="index">
					<view :class="[activeIndex === index? 'active':'','left-scroll-item']" @click="handactive(index)">{{item.cat_name}}</view>
				</block>
			</scroll-view>
			<scroll-view class="right-scroll-view" scroll-y :style="'height:'+ wh +'px'" :scroll-top="scrollTop">
				<view class="right-scroll-item" v-for="(i,index) in cateList2" :key="index">
					<view class="title">/{{i.cat_name}}/</view>
					<view class="right-scroll-list">
						<view class="right-scroll-box" v-for="(j,key) in i.children" :key="key" @click="gotoGoodsList(j)">
							<image :src="j.cat_icon"></image>
							<text>{{ j.cat_name }}</text>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabber-badge.js'
	export default {
		mixins: [badgeMix],
		data() {
			return {
				wh: 0,
				activeIndex: 0,
				cateList: [],
				cateList2: [],
				scrollTop: 0
			}
		},
		onLoad(){
			const sysInfo = uni.getSystemInfoSync()
			this.wh = sysInfo.windowHeight - 50
			this.getCateList()
		},
		methods: {
			async getCateList(){
				const { data } = await uni.$http.get("/categories")
				if(data.meta.status !== 200) return uni.$showMsg()
				this.cateList = data.message
				this.cateList2 = data.message[0].children
			},
			handactive(index){
				this.activeIndex = index
				this.cateList2 = this.cateList[index].children
				this.scrollTop = this.scrollTop === 0?1:0
			},
			jump(){
				uni.navigateTo({url: "/subpkg/search/search"})
			},
			gotoGoodsList(item){
				uni.navigateTo({
					url: '/subpkg/goods_list/goods_list?cid=' + item.cat_id
				})
			}
		}
	}
</script>

<style lang="scss">
	.content{
		display: flex;
		.left-scroll-view{
			width: 120px;
			text-align: center;
			.left-scroll-item{
				background-color: #f7f7f7;
				font-size: 12px;
				line-height: 60px;
				position: relative;
				&.active{
					background-color: #fff;
					&::before{
						content: '';
						display: block;
						width: 3px;
						height: 30px;
						background-color: #C00000;
						position: absolute;
						top: 50%;
						left: 0;
						transform: translateY(-50%)
					}
				}
			}
		}
		.right-scroll-item{
			.title{
				font-weight: bold;
				font-size: 12px;
				text-align: center;
				padding: 20px 0;
			}
			image{
				width: 60px;
				height: 60px;
			}
		}
		.right-scroll-list{
			display: flex;
			flex-wrap: wrap;
			.right-scroll-box{
				width: 33.33%;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				margin-bottom: 15px;
				text{
					font-size: 12px;
				}
			}
		}
	}
</style>
